var UIPanel_BetRecord = (function () {
    function UIPanel_BetRecord() {
        this.panel = null;
        this.typePlace = 2;
        this.typeAward = 2;
        this.pageText = 1;
    }

    var __proto = UIPanel_BetRecord.prototype;
    __proto.init = function () {
        var btn_back = this.panel.getChild("btn_back");
        btn_back.onClick(this, function () {
            this.panel.visible = false;
        });
        this.dropDownMenu = this.panel.getChild("dropDownMenu");
        this.dropDownList = this.panel.getChild("dropDownList").getChild("list");
        this.list = this.panel.getChild("list");
        this.pageNum = this.panel.getController("page");

        this.btn_RR = this.panel.getChild("btn_RR");
        this.btn_R = this.panel.getChild("btn_R");
        this.btn_L = this.panel.getChild("btn_L");
        this.btn_LL = this.panel.getChild("btn_LL");
        this.page_L = this.panel.getChild("page_L");
        this.page_R = this.panel.getChild("page_R");
        this.num1 = this.panel.getChild("num1");
        this.num2 = this.panel.getChild("num2");

        this.page_L.text = 1;
        this.page_R.text = 1;
        this.num1.text = 0;
        this.num2.text = 0;

        this.btn_RR.onClick(this, this.clickEnd);
        this.btn_R.onClick(this, this.clickNextPage);
        this.btn_L.onClick(this, this.clickPreviousPage);
        this.btn_LL.onClick(this, this.clickBegin);

        //this.list.removeChildren();

        for (var i = 1; i <= 3; i++) {
            var btn = this.panel.getChild("btn" + i);
            btn.onClick(this, this.selectBtns);
            if (i === 3) {
                btn.getChild("bg").color = '#FE7000';
            }
            if (i === 2) {
                btn.getChild("bg").color = '#888888';
            }
        }
        this.initDropDownList(test_dropDownData);
    }
    var test_dropDownData = ['全部游戏', '北京玩法', '江苏玩法'];

    __proto.initList = function (data) {
        this.list.removeChildren();
        this.pageNum.clearPages();
        console.log(data);
        if (!data) {
            return;
        }
        for (var i in data.list) {
            var item = this.list.addItemFromPool();
            var info = data.list[i];
            switch (info.gameType) {
                case 0:
                    item.getChild('name').text = '北京玩法';
                    break;
                case 1:
                    item.getChild('name').text = '江苏玩法';
                    break;
            }
            item.getChild('period').text = info.indexId + '期';
            item.getChild('id').text = info.id;
            item.getChild('sign').text = '总输赢';
            item.getChild('num1').text = '';
            item.getChild('num2').text = info.winCoins;
            item.getChild('state').text = info.winCoins > 0 ? '已中奖' : '未中奖';
            if (info.winCoins > 0) {
                item.getChild('bg4').color = '#FE7000';
            }
            item.getChild('time').text = Util.dateFormatYMDHMS(new Date(info.createTime));
            var betList = item.getChild('list');
            betList.removeChildren();
            var jsonBetList = JSON.parse(info.betList)
            for (var j in jsonBetList) {
                var betItem = betList.addItemFromPool();
                var betInfo = jsonBetList[j].replace(/\[|\]/g, '').split(",");
                var index = parseInt(j)
                if (index >= 5 && index <= 10) {
                    var t = index - 4;
                    betItem.getChild('sign').text = '单选@' + t;
                }
                if (index >= 11 && index <= 25) {
                    switch (index) {
                        case 11: betItem.getChild('sign').text = '2中2@' + '1,2'; break;
                        case 12: betItem.getChild('sign').text = '2中2@' + '1,3'; break;
                        case 13: betItem.getChild('sign').text = '2中2@' + '1,4'; break;
                        case 14: betItem.getChild('sign').text = '2中2@' + '1,5'; break;
                        case 15: betItem.getChild('sign').text = '2中2@' + '1,6'; break;
                        case 16: betItem.getChild('sign').text = '2中2@' + '2,3'; break;
                        case 17: betItem.getChild('sign').text = '2中2@' + '2,4'; break;
                        case 18: betItem.getChild('sign').text = '2中2@' + '2,5'; break;
                        case 19: betItem.getChild('sign').text = '2中2@' + '2,6'; break;
                        case 20: betItem.getChild('sign').text = '2中2@' + '3,4'; break;
                        case 21: betItem.getChild('sign').text = '2中2@' + '3,5'; break;
                        case 22: betItem.getChild('sign').text = '2中2@' + '3,6'; break;
                        case 23: betItem.getChild('sign').text = '2中2@' + '4,5'; break;
                        case 24: betItem.getChild('sign').text = '2中2@' + '4,6'; break;
                        case 25: betItem.getChild('sign').text = '2中2@' + '5,6'; break;
                    }

                }
                if (index >= 26 && index <= 45) {
                    switch (index) {
                        case 26: betItem.getChild('sign').text = '3中2@' + '1,2,3'; break;
                        case 27: betItem.getChild('sign').text = '3中2@' + '1,2,4'; break;
                        case 28: betItem.getChild('sign').text = '3中2@' + '1,2,5'; break;
                        case 29: betItem.getChild('sign').text = '3中2@' + '1,2,6'; break;

                        case 30: betItem.getChild('sign').text = '3中2@' + '1,3,4'; break;
                        case 31: betItem.getChild('sign').text = '3中2@' + '1,3,5'; break;
                        case 32: betItem.getChild('sign').text = '3中2@' + '1,3,6'; break;

                        case 33: betItem.getChild('sign').text = '3中2@' + '1,4,5'; break;
                        case 34: betItem.getChild('sign').text = '3中2@' + '1,4,6'; break;

                        case 35: betItem.getChild('sign').text = '3中2@' + '1,5,6'; break;

                        case 36: betItem.getChild('sign').text = '3中2@' + '2,3,4'; break;
                        case 37: betItem.getChild('sign').text = '3中2@' + '2,3,5'; break;
                        case 38: betItem.getChild('sign').text = '3中2@' + '2,3,6'; break;

                        case 39: betItem.getChild('sign').text = '3中2@' + '2,4,5'; break;
                        case 40: betItem.getChild('sign').text = '3中2@' + '2,4,6'; break;

                        case 41: betItem.getChild('sign').text = '3中2@' + '2,5,6'; break;

                        case 42: betItem.getChild('sign').text = '3中2@' + '3,4,5'; break;
                        case 43: betItem.getChild('sign').text = '3中2@' + '3,4,6'; break;
                        case 44: betItem.getChild('sign').text = '3中2@' + '3,5,6'; break;
                        case 45: betItem.getChild('sign').text = '3中2@' + '4,5,6'; break;

                    }
                }
                switch (index) {
                    case 0: betItem.getChild('sign').text = '大@'; break;
                    case 1: betItem.getChild('sign').text = '小@'; break;
                    case 2: betItem.getChild('sign').text = '单@'; break;
                    case 3: betItem.getChild('sign').text = '双@'; break;
                    case 4: betItem.getChild('sign').text = '三全@'; break;
                }
                betItem.getChild('num1').text = '';
                betItem.getChild('num2').text = betInfo[0];
                betItem.getChild('num3').text = betInfo[1];
            }


        }
        var count = Math.ceil(data.count / 7);
        //this.pageNum.pageCount = count;
        for (var i = 0; i < count; i++) {
            this.pageNum.addPage();
            console.log(this.pageNum.pageCount)
        }
        this.initPage(this.pageNum.pageCount);
        this.list.on(fairygui.Events.CLICK_ITEM, this, this.clickItem);
    }
    __proto.clickItem = function (obj) {
        console.log("clickItem  ", obj.title);
        this.list.title = obj.title;
    }
    __proto.initDropDownList = function (data) {
        this.dropDownList.removeChildren();
        if (!data) {
            return;
        }
        var h = 0;
        for (var i in data) {
            var item = this.dropDownList.addItemFromPool();
            h = item.height;
            item.title = data[i];
        }
        this.dropDownList.height = data.length * h;
        this.dropDownList.on(fairygui.Events.CLICK_ITEM, this, this.clickDropDownItem);
    }
    __proto.clickDropDownItem = function (obj) {
        console.log("clickItem  ", obj.title);
        this.dropDownMenu.title = obj.title;
        this.dropDownMenu.selected = false;
        switch (obj.title) {
            case '北京玩法':
                this.typePlace = 0;
                break;
            case '江苏玩法':
                this.typePlace = 1;
                break;
            case '全部游戏':
                this.typePlace = 2;
                break;
        }
        this.getData(this.typePlace, this.typeAward, 1);
        pagePre = 1;
        this.setPage(pagePre);
    }
    __proto.selectBtns = function (e) {
        var item = e.target.$owner;
        var title = item.title;

        if (title == '已中奖') {
            console.log(item.selected)
            this.typeAward = 0;
        }
        if (title == '未中奖') {
            console.log(item.selected)

            this.typeAward = 1;
        }
        if (title == '全部') {
            console.log(item.selected)
            this.typeAward = 2;
        }
        this.getData(this.typePlace, this.typeAward, 1);
        pagePre = 1;
        this.setPage(pagePre);
        console.log("Gold  ", title);
    }

    var pagePre = 1;
    __proto.clickBegin = function (e) {
        console.log("首页");

        pagePre = 1;
        this.pageText = pagePre;
        this.setPage(pagePre);
        this.getData(this.typePlace, this.typeAward, this.pageText);
    }
    __proto.clickEnd = function (e) {
        console.log("尾页");

        pagePre = this.pageNum.pageCount;
        this.pageText = pagePre;
        this.setPage(pagePre);
        this.getData(this.typePlace, this.typeAward, this.pageText);
    }
    __proto.clickPreviousPage = function (e) {
        console.log("上一页 " + pagePre, this.pageNum.pageCount);

        if (pagePre <= 1) {
            Tip.instance().show('已经是第一页');
            pagePre = 1;
            return;
        }
        pagePre--;

        this.pageText = pagePre;
        this.setPage(pagePre);
        this.getData(this.typePlace, this.typeAward, this.pageText);
    }
    __proto.clickNextPage = function (e) {
        console.log("下一页 " + pagePre, this.pageNum.pageCount);

        if (pagePre >= this.pageNum.pageCount) {
            Tip.instance().show('已经是最后一页');
            pagePre = this.pageNum.pageCount;
            return;
        }
        pagePre++;

        this.pageText = pagePre;
        this.setPage(pagePre);
        this.getData(this.typePlace, this.typeAward, this.pageText);
    }
    __proto.initPage = function (v) {
        this.page_R.text = v;
    }
    __proto.setPage = function (v) {
        this.page_L.text = v;
    }
    __proto.setNum1 = function (value) {
        this.num1.text = value;
    }
    __proto.setNum2 = function (value) {
        this.num2.text = value;
    }



    __proto.getData = function (typePlace, typeAward, page) {
        var self = this;
        NetHttp.getBetRecord(typePlace, typeAward, page).then(function (res) {
            var data = res.data;
            console.log(data);
            if (data.code === 200) {
                var betList = new Array();
                for (var i in data.data) {
                    betList.push(data.data[i].betList)
                }
                self.initList(data.data);
            }
        }).catch(function (err) {
            if (err.message.indexOf('Network Error') >= 0) {
                console.log("网络连接失败, 请稍后再试");
                return;
            }
            console.log(err);
        });
    }




    return UIPanel_BetRecord;
})()
